package cn.tedu.spring.dibase;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BookTest {

    /* 1.原生set注入属性 */
    @Test
    public void setTest(){
        Book book = new Book();
        book.setBookName("花千骨");
        book.setBookAuthor("赵丽颖");
        System.out.println("book = " + book);
    }

    /* 2.原生构造器注入属性 */
    @Test
    public void ConsTest(){
        Book book = new Book("杉杉来了", "赵丽颖");
        System.out.println("book = " + book);
    }

    /* 3.通过spring set方法注入属性 */
    @Test
    public void SpringSetTest(){
        /**
         1.加载xml配置文件
         2.获取指定bean对象
         3.测试
         */
        ApplicationContext context = new ClassPathXmlApplicationContext("bean-di.xml");
        Book book = context.getBean("book", Book.class);
        System.out.println("book = " + book);
    }

    /* 3.通过spring 构造器方式注入属性 */
    @Test
    public void SpringConsTest(){
        /**
         1.加载xml配置文件
         2.获取指定bean对象
         3.测试
         */
        ApplicationContext context = new ClassPathXmlApplicationContext("bean-di.xml");
        Book book = context.getBean("bookCons", Book.class);
        System.out.println("bookCons = " + book);
    }
}
